package com.mdd.admin.controller.system;


import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.system.*;
import com.mdd.admin.validate.course.CourseParam;
import com.mdd.admin.validate.system.*;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.utils.LsConfigUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 知识付费系统配置
 */
@RestController
@RequestMapping("api/ls/system/config")
public class LsSystemConfigController {

    @Resource
    ISystemRchargeConfigService systemRchargeConfigService;

    @Resource
    ISystemTransactionConfigService systemTransactionConfigService;

    @Resource
    ISystemPointDeductionConfigService systemPointDeductionConfigService;

    @Resource
    ISystemConsumptionRewardConfigService systemConsumptionRewardConfigService;

    @Resource
    ISystemSignInConfigService systemSignInConfigService;

    /**
     * 获取消费奖励规则详情
     *
     * @author panweiliang
     * @return AjaxResult
     */
    @GetMapping("/consumption_reward/detail")
    public AjaxResult consumptionRewardDetail() {
        return AjaxResult.success(LsConfigUtil.get("consumption_reward"));
    }

    /**
     * 消费奖励规则规则编辑
     *
     * @param systemConsumptionRewardConfigParam 参数
     * @return Object
     */
    @Log(title = "消费奖励规则编辑")
    @PostMapping("/consumption_reward/edit")
    public Object addOrUpdateConsumptionReward(@Validated(value = SystemConsumptionRewardConfigParam.update.class) @RequestBody SystemConsumptionRewardConfigParam systemConsumptionRewardConfigParam) {
        this.systemConsumptionRewardConfigService.addOrUpdate(systemConsumptionRewardConfigParam);
        return AjaxResult.success(true);
    }

    /**
     * 获取积分抵扣规则详情
     *
     * @author panweiliang
     * @return AjaxResult
     */
    @GetMapping("/point_deduction/detail")
    public AjaxResult pointDeductionDetail() {
        return AjaxResult.success(LsConfigUtil.get("point_deduction"));
    }

    /**
     * 积分抵扣规则编辑
     *
     * @param systemPointDeductionConfingParam 参数
     * @return Object
     */
    @Log(title = "积分抵扣规则编辑")
    @PostMapping("/point_deduction/edit")
    public Object addOrUpdatePointDeduction(@Validated(value = SystemPointDeductionConfingParam.update.class) @RequestBody SystemPointDeductionConfingParam systemPointDeductionConfingParam) {
        this.systemPointDeductionConfigService.addOrUpdate(systemPointDeductionConfingParam);
        return AjaxResult.success(true);
    }

    /**
     * 获取用户充值规则详情
     *
     * @author panweiliang
     * @return AjaxResult
     */
    @GetMapping("/recharge/detail")
    public AjaxResult detail() {
        return AjaxResult.success(LsConfigUtil.get("recharge"));
    }

    /**
     * 用户充值规则编辑
     *
     * @param systemRchargeConfingParam 参数
     * @return Object
     */
    @Log(title = "用户充值规则编辑")
    @PostMapping("/recharge/edit")
    public Object addOrUpdate(@Validated(value = SystemRchargeConfingParam.update.class) @RequestBody SystemRchargeConfingParam systemRchargeConfingParam) {
        this.systemRchargeConfigService.addOrUpdate(systemRchargeConfingParam);
        return AjaxResult.success(true);
    }

    /**
     * 获取交易配置详情
     *
     * @author panweiliang
     * @return AjaxResult
     */
    @GetMapping("/transaction/detail")
    public AjaxResult transactionDetail() {
        return AjaxResult.success(LsConfigUtil.get("transaction"));
    }

    /**
     * 交易配置编辑
     *
     * @param systemTransactionCancelUnpaidOrderConfingParam 参数
     * @return Object
     */
    @Log(title = "交易配置编辑")
    @PostMapping("/transaction/edit")
    public Object addOrUpdate(@Validated(value = SystemTransactionCancelUnpaidOrderConfingParam.update.class) @RequestBody SystemTransactionCancelUnpaidOrderConfingParam systemTransactionCancelUnpaidOrderConfingParam) {
        this.systemTransactionConfigService.addOrUpdateCancelUnpaidOrdersConfig(systemTransactionCancelUnpaidOrderConfingParam);
        return AjaxResult.success(true);
    }

    /**
     * 签到奖励规则配置详情
     *
     * @author panweiliang
     * @return AjaxResult
     */
    @GetMapping("/sign-in/detail")
    public AjaxResult signInDetail() {
        return AjaxResult.success(LsConfigUtil.get("sign-in_points"));
    }

    /**
     * 交易配置编辑
     *
     * @param systemSignInConfingParam 参数
     * @return Object
     */
    @Log(title = "签到奖励规则编辑")
    @PostMapping("/sign-in/edit")
    public Object addOrUpdateSignIn(@Validated(value = SystemSignInConfingParam.update.class) @RequestBody SystemSignInConfingParam systemSignInConfingParam) {
        this.systemSignInConfigService.addOrUpdateSignInConfig(systemSignInConfingParam);
        return AjaxResult.success(true);
    }

}
